#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 10010;

vector<int> arr1;
vector<int> arr2;

int m, n;

int main() {
    cin >> m >> n;
    int x;
    for (int i = 0; i < m; i++)
    {
        cin >> x;
        arr1.push_back(x);
    }
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        arr2.push_back(x);
    }
    sort(arr1.begin(), arr1.end());
    sort(arr2.begin(), arr2.end());


    int cur1 = 0, cur2 = 0;

    while (cur1 < m && cur2 < n) {
        if (arr1[cur1] == arr2[cur2]) cur1++;
        else if (arr1[cur1] < arr2[cur2]) {
            cout << arr1[cur1] << " ";
            cur1++;
        }
        else {
            cout << arr2[cur2] << " ";
            cur2++;
        }
    }

    while (cur1 < m) cout << arr1[cur1++] << " ";
    while (cur2 < n) cout << arr2[cur2++] << " ";

    return 0;
}
//#include <iostream>
//using namespace std;
//
//int n = 0;
//
//int main()
//{
//    cin >> n;
//
//    int left = 1, right = n;
//
//    while (left <= right)
//    {
//        cout << left << " ";
//        left++;
//        if (left <= right)
//        {
//            cout << right << " ";
//            right--;
//        }
//    }
//
//    return 0;
//}